package com.my.mybatis.generator.dao;

import com.my.mybatis.generator.entity.Order;
import com.my.mybatis.generator.entity.User;
import com.my.mybatis.generator.entity.example.UserExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface UserMapper {
    int countByExample(UserExample example);

    int deleteByExample(UserExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExample(UserExample example);

    User selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    @Select("select id from user where username = #{username}")
    int selectIdFromName(String username);

    @Select("SELECT * from `order` LEFT JOIN `user` on `order`.user_id = `user`.id")
    List<Map<String,Object>> selectAllUserAndOrder();

    List<User> getAllUserAndOrder();

    User selectUserAndOrdersById(Integer id);

    List<Order> selectOrdersByUserId(Integer userId);

    @Select("select * from user")
    List<User> getAll();
}